/**
 * 
 */
package com.hsxc.cdz.mgmt.user;

import java.util.ArrayList;
import java.util.List;


import org.apache.shiro.dao.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.hsxc.cdz.base.bean.ConsoleUser;
import com.hsxc.cdz.base.dao.ConUserDao;
/**
 * @author wpfei
 * @version
 */

@Component
public class UserManager implements UserManagerIntf {

	/**
	 * 
	 */
  private int USERTYPE =0 ;
	
   @Autowired
   private ConUserDao conuserdao;
   
	@Override
	@Transactional 
	public ConsoleUser userConLogin(ConsoleUser consoleUser) {
		return conuserdao.findConUser(consoleUser);
	}

	@Override
	public int insertConUser(ConsoleUser consoleUser) {
		return conuserdao.insertConUser(consoleUser);
	}

	@Override
	public int deleteConUser(int id) {
		return conuserdao.deleteConUser(id);
	}

	@Override
	public int updateConUser(ConsoleUser consoleUser) {
		return conuserdao.updateConUser(consoleUser);
	}

	@Override
	public List<ConsoleUser> findAllConUsers() {
		return conuserdao.findAllConUsers();
	}

	
	@Override
	public ConsoleUser loadConUserByName(String userName) {
		
		ConsoleUser consoleUser = new ConsoleUser();
			try{
				consoleUser.setUser_name(userName);
				consoleUser= conuserdao.findConUser(consoleUser);
			}
			catch (DataAccessException e) {
				e.printStackTrace();
			}
			return consoleUser;
		}
	@Override
	public List<String> getUserRoles(String userName) {
		List<String> roles = null;
		try{
		  roles = conuserdao.getConUserRoles(userName);  	
		}
		catch(DataAccessException e){
			e.printStackTrace();
		}
		return roles;
	//	return null;
		
	}

	@Override
	public List<ConsoleUser> findConUserByRole(ConsoleUser consoleUser) {
		List<ConsoleUser> consoleUsers = null;
		try{
			consoleUsers = conuserdao.findConUserByRole(consoleUser);
		}
		catch(DataAccessException e){
			e.printStackTrace();
		}
		return consoleUsers;
	//	return null;
		
	}
	
	@Override
	public List<String> findStationAdmin(ConsoleUser consoleUser) {
		 List<String> stationAdmin=new ArrayList<String>();
		// ConsoleUser consoleUser = new ConsoleUser();
		 try{
		
			 stationAdmin = conuserdao.findStationAdmin(consoleUser);
		 }
		 catch(DataAccessException e){
				e.printStackTrace();
			}
		 return stationAdmin;
		 
	}

	
	@Override
	public List<String> findAllOperators(ConsoleUser consoleUser) {
		
		return null;
	}

	

	@Override
	public ConsoleUser findOperatorByNo(String operatorNO) {
		ConsoleUser consoleUser =new ConsoleUser();
		try{
		consoleUser.setOperatorNO(operatorNO);
		consoleUser= conuserdao.findConUser(consoleUser);
		}
		catch (DataAccessException e) {
			e.printStackTrace();
		}
		return consoleUser;

	}

	@Override
	public ConsoleUser loadConUserBySsid(int ssid) {
		ConsoleUser consoleUser =new ConsoleUser();
		try{
		consoleUser.setSsid(ssid);
		consoleUser= conuserdao.findConUser(consoleUser);
		}
		catch (DataAccessException e) {
			e.printStackTrace();
		}
		return consoleUser;
		
	}

	
	@Override
	public ConsoleUser loadConUserByMobile(String mobile) {
		ConsoleUser consoleUser = new ConsoleUser();
		consoleUser.setMobile(mobile);		
		return  conuserdao.findConUser(consoleUser);

	}
	
	@Override
	public int updateConUserPassword(ConsoleUser consoleUser) {
		
		return conuserdao.updateConUserPassword(consoleUser);
	}
	
   //设置用户类型参数
	public int getUSERTYPE() {
		return USERTYPE;
	}

	public void setUSERTYPE(int uSERTYPE) {
	   this.USERTYPE = uSERTYPE;
	}

	@Override
	public int lockAccount(ConsoleUser consoleUser) {
		System.out.println("====================锁账户========================================");
		return conuserdao.updateConUser(consoleUser);
	}

	@Override
	public int unlockAccount(ConsoleUser consoleUser) {
		
		return conuserdao.updateConUser(consoleUser);
	}

	
	


	

}
